/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package network;

import controllers.DatabaseController;
import listcontrol.LocalFileList;
import java.io.IOException;
import java.net.ServerSocket;

/**
 *
 * @author gravena
 */
public class ListRequestListener implements Runnable {
    private ServerSocket listener;    
    private DatabaseController dbController;
    public static final int LIST_REQUEST_PORT = 40100;
    
    public ListRequestListener(DatabaseController dbController) {        
        this.dbController = dbController;
        try {
            this.listener = new ServerSocket(LIST_REQUEST_PORT);
        } catch (IOException ex) {
            System.err.println("Erro ao criar ServerSocket\n" + ex.getMessage());
        }
    }
    
    @Override
    public void run() {
        while(true) {
            try {                
                new Thread(new ListRequestHandler(dbController, this.listener.accept())).start();
            } catch (IOException ex) {
                System.err.println("Erro no estabelecimento de conexão!\n" + ex.getMessage());
            }
        }
    }
}
